#include <stdio.h>
#include <stdlib.h>
#include "gdst_array.h"

int array_test_add(void)
{
	int errors = 0;
	int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	size_t i;
	array_p array = gdst_arraynew(2, sizeof(int));
	if (!array)
		return 0;
	for (i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
	{
		errors += gdst_arraypush(array, &a[i]);
	}
	for (i = 0; i < gdst_arraycount(array); ++i)
	{
		int *value = (int *)gdst_arraygetat(array, i);
		if (i % 2)
			*value = 10;
		printf("%d ", *value);
	}
	gdst_arrayfree(&array);
	return errors != 0 ? 0 : 1;
}

int array_test_rem(void)
{
	int errors = 0;
	int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	size_t i;
	array_p array = gdst_arraynew(2, sizeof(int));
	if (!array)
		return 0;
	for (i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
	{
		errors += gdst_arraypush(array, &a[i]);
	}

	for (i = 0; i < gdst_arraycount(array); ++i)
	{
		if (i % 3 == 0) {
			errors += gdst_arrayremat(array, i);
		}
	}
	for (i = 0; i < gdst_arraycount(array); ++i)
	{
		int *value = (int *)gdst_arraygetat(array, i);
		printf("%d ", *value);
	}
	gdst_arrayfree(&array);
	return errors != 0 ? 0 : 1;
}

int main(int argc, char *argv[])
{
	printf("array_test_add: ");
	if (array_test_add())
		printf(" PASS\n");
	else
		printf(" FAIL\n");
	if (array_test_rem())
		printf(" PASS\n");
	else
		printf(" FAIL\n");
	return 0;
}
